import java.util.ArrayList;
import java.util.List;

public class Hall {
    private String hallName;
    private int rowCount;
    private int colCount;
    private Seat[][] seats; // 座位矩阵（行×列）

    public Hall(String hallName, int rowCount, int colCount) {
        this.hallName = hallName;
        this.rowCount = rowCount;
        this.colCount = colCount;
        initSeats(); // 初始化座位
    }

    // 初始化座位（默认未售出）
    private void initSeats() {
        seats = new Seat[rowCount][colCount];
        for (int i = 0; i < rowCount; i++) {
            for (int j = 0; j < colCount; j++) {
                seats[i][j] = new Seat(i + 1, j + 1, false); // 行号、列号从1开始
            }
        }
    }

    // 检查座位是否可用
    public boolean checkSeatAvailable(int row, int col) {
        // 检查行号列号是否合法
        if (row < 1 || row > rowCount || col < 1 || col > colCount) {
            return false;
        }
        // 检查座位是否已售出
        return !seats[row - 1][col - 1].isSold();
    }

    // 锁定座位（售票）
    public boolean lockSeats(List<Seat> seatsToLock) {
        for (Seat seat : seatsToLock) {
            int row = seat.getRow();
            int col = seat.getCol();
            if (!checkSeatAvailable(row, col)) {
                return false; // 有座位不可用，锁定失败
            }
            seats[row - 1][col - 1].setSold(true); // 标记为已售出
        }
        return true;
    }

    // 解锁座位（退票）
    public void unlockSeats(List<Seat> seatsToUnlock) {
        for (Seat seat : seatsToUnlock) {
            int row = seat.getRow();
            int col = seat.getCol();
            if (row >= 1 && row <= rowCount && col >= 1 && col <= colCount) {
                seats[row - 1][col - 1].setSold(false); // 标记为未售出
            }
        }
    }

    // getter和setter
    public String getHallName() {
        return hallName;
    }

    public int getRowCount() {
        return rowCount;
    }

    public int getColCount() {
        return colCount;
    }

    public Seat[][] getSeats() {
        return seats;
    }
}
    